﻿package Gameplay.Visualizer
{	
	public class PlasmaCircle 
	{
		private var FVertices:Vector.<Vertex>;
		private var FRadius:Number;
		private var FSlice:uint;
		
		public function PlasmaCircle(ARadius:Number=100, ASlice:uint=512):void 
		{
			FVertices = new Vector.<Vertex>();
			FRadius = ARadius;
			FSlice = ASlice;
			
			var vDegree:Number = 3*Math.PI/2;
			
			for (var i:uint = 0; i < FSlice; i++)
			{
				FVertices.push(new Vertex(FRadius, vDegree));
				vDegree += 2 * Math.PI / FSlice;
			}
		}
		
		public function get Vertices():Vector.<Vertex> 
		{
			return FVertices;
		}
		
		public function set Radius(value:Number):void 
		{
			FRadius = value;
			for each(var v:Vertex in FVertices) 
			{
				v.Radius = value;
			}
		}
		
		public function Update(level:Vector.<Number>):void 
		{
			for (var i:uint=0; i<level.length; i++) 
			{
				if (FVertices[i].Radius > FRadius + level[i]) 
				{
					FVertices[i].Radius = Math.max(FRadius, FVertices[i].Radius - 5);
				} 
				else 
				{
					FVertices[i].Radius = Math.max(FVertices[i].Radius, FRadius + level[i]);
				}
			}
		}
	}	
}
